package com.maduar.demo.thread;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Description:
 *
 * @author maduar maduar@163.com
 * @date 2021-05-06 22:21
 */
public class Singleton2 {

    private Singleton2() {
    }

    public static Lock lock = new ReentrantLock();
    public static volatile Singleton2 instance;

    public static Singleton2 getInstance() {
        if (instance == null) {
            try {
                lock.lock();
                if (instance == null) {
                    instance = new Singleton2();
                }
            } finally {
                lock.unlock();
            }
        }
        return instance;
    }
}
